package cn.wolfcode.luowowo.acticle.service.impl;



import cn.wolfcode.luowowo.acticle.domain.TravelTag;
import cn.wolfcode.luowowo.acticle.mapper.TravelTagMapper;
import cn.wolfcode.luowowo.acticle.service.ITravelTagService;
import cn.wolfcode.luowowo.common.exception.DisplayableException;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
@Service
@Transactional
public class TravelTagServiceImpl implements ITravelTagService {

    @Autowired
    private TravelTagMapper travelTagMapper;


    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(travelTagMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(TravelTag travelTag) throws DisplayableException {
        if(travelTag.getId() == null){
            travelTagMapper.insert(travelTag);
        }else{
            travelTagMapper.updateByPrimaryKey(travelTag);
        }
    }

    @Override
    public void delete(Long id) throws DisplayableException {
        travelTagMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<TravelTag> list() {
        return travelTagMapper.selectAll();
    }

    @Override
    public List<String> getTagByTravelId(Long travelId) {
        return travelTagMapper.selectTagByTravelId(travelId);
    }
}
